package com.kensure.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import co.kensure.frame.ResultInfo;
import co.kensure.frame.ResultRowInfo;
import co.kensure.frame.ResultRowsInfo;
import co.kensure.http.RequestUtils;
import co.kensure.mem.PageInfo;

import com.alibaba.fastjson.JSONObject;
import com.kensure.shike.changshang.model.ChangShang;
import com.kensure.shike.changshang.service.ChangShangService;

/**
 * 厂商管理
 * 
 * @author fankaidi
 *
 */
@Controller
@RequestMapping(value = "changshang")
public class ChangShangController {

	@Resource
	private ChangShangService changShangService;



	/**
	 * 类型内容
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "get.do", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public ResultInfo get(HttpServletRequest req, HttpServletResponse rep) {
		JSONObject json = RequestUtils.paramToJson(req);
		Long id = json.getLong("id");
		ChangShang cms = changShangService.selectOne(id);
		return new ResultRowInfo(cms);
	}

	/**
	 * 后台信息列表
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "alllist.do", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public ResultInfo alllist(HttpServletRequest req, HttpServletResponse rep) {
		JSONObject json = RequestUtils.paramToJson(req);
		PageInfo page = JSONObject.parseObject(json.toJSONString(), PageInfo.class);
		List<ChangShang> list = changShangService.selectByWhere(page);
		Long count = changShangService.selectCountByWhere(null);
		return new ResultRowsInfo(list, count);
	}

	/**
	 * 保存
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "save.do", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public ResultInfo save(HttpServletRequest req, HttpServletResponse rep) {
		JSONObject json = RequestUtils.paramToJson(req);
		ChangShang obj = JSONObject.parseObject(json.toJSONString(), ChangShang.class);
		changShangService.add(obj);
		return new ResultRowInfo();
	}

}
